import { defineStore } from 'pinia'
import { requestPoetryByPid, requestCollectPoetry, queryCollectPoetryInfo, requestPoemsListByUid, requestAddPoetryToPoemsList } from './poetry-detail.api'

export default defineStore('poetryDetail', {
    state: () => {
        return {
        }
    },
    getters: {
    },
    actions: {
        getPoetryByPid(data: Object = {}) {
            return new Promise((resolve, reject) => {
                requestPoetryByPid(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },
        collectPoetry(data: Object = {}) {
            return new Promise((resolve, reject) => {
                requestCollectPoetry(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },
        getCollectPoetryInfo(data: Object = {}) {
            return new Promise((resolve, reject) => {
                queryCollectPoetryInfo(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },
        // 获取用户的诗单信息
        getPoemsListByUid(data: Object = {}) {
            return new Promise((resolve, reject) => {
                requestPoemsListByUid(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },
        // 将诗词加入诗单
        getAddPoetryToPoemsList(data: Object = {}) {
            return new Promise((resolve, reject) => {
                requestAddPoetryToPoemsList(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },
        
    }
})
